<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Bags
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot050.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot049.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot052.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc128">9.2</A>&nbsp;&nbsp;Bags</H2>

A bag is an anonymous object which can be used to store
information across failures.
A bag is unordered and untyped. Any ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> term can be stored in a bag.
Bags are referred to by a handle.
An empty bag is created using
<A HREF="../bips/kernel/storage/bag_create-1.html"><B>bag_create/1</B></A><A NAME="@default441"></A>,
data is stored in the bag by invoking
<A HREF="../bips/kernel/storage/bag_enter-2.html"><B>bag_enter/2</B></A><A NAME="@default442"></A>,
and the stored data can be retrieved as a list with
<A HREF="../bips/kernel/storage/bag_retrieve-2.html"><B>bag_retrieve/2</B></A><A NAME="@default443"></A> or
<A HREF="../bips/kernel/storage/bag_dissolve-2.html"><B>bag_dissolve/2</B></A><A NAME="@default444"></A>.<BR>
<BR>
A typical application is the
implementation of the findall/3 predicate or similar functionality. 
As opposed to the use of record/2 or assert/1, the solution using
bags is more efficient, more robust, and trivially reentrant.
<PRE CLASS="verbatim">
    simple_findall(Goal, Solutions) :-
        bag_create(Bag),
        (
            call(Goal),
            bag_enter(Bag, Goal),
            fail
        ;
            true
        ),
        bag_dissolve(Bag, Solutions).
</PRE>
<HR>
<A HREF="umsroot050.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot049.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="umsroot052.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
